#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

FOUNDATION_EXTERN NSString *const kKeyChainUserId;
FOUNDATION_EXTERN NSString *const kKeyChainToken;
FOUNDATION_EXPORT NSString *const kKeyChainTokenType;

@interface SHKeychain : NSObject

/**
 bundleID 如: com.Example.auto
 */
@property (nonatomic, copy, class, readonly) NSString *defaultServiceName;

@property (nonatomic, copy, nullable, class, readonly) NSString *appIdentifierPrefix;
@property (nonatomic, copy, nullable, class, readonly) NSString *availableAccessGroup;


/**
 * service name为defaultServiceName即main bundleId，group 为 nil
 */
+ (nullable NSString *)passwordForAccount:(NSString *)account;

/**
 保存

 @param account account
 @param password passwork
 @return 成功true, 失败false
 */
+ (BOOL)storeAccount:(NSString *)account password:(NSString *)password;

/**
 删除

 @param account account
 @return 成功true, 失败false
 */
+ (BOOL)deletePasswordForAccount:(NSString *)account;

/*
 * group 为 nil
 */
+ (nullable NSString *)passwordForAccount:(NSString *)account service:(NSString *)serviceName;
+ (BOOL)storeAccount:(NSString *)account password:(NSString *)password service:(NSString *)serviceName;
+ (BOOL)deletePasswordForAccount:(NSString *)account serviceName:(NSString *)serviceName;

+ (nullable NSString *)passwordForAccount:(NSString *)account
                                  service:(NSString *)serviceName
                                    group:(nullable NSString *)keychainGroup
                                    error:(NSError *_Nullable __autoreleasing *)error;
+ (BOOL)storeAccount:(NSString *)account
            password:(NSString *)password
             service:(NSString *)serviceName
               group:(nullable NSString *)keychainGroup
      updateExisting:(BOOL)updateExisting
               error:(NSError *_Nullable __autoreleasing *)error;
+ (BOOL)storeAccount:(NSString *)account
            password:(NSString *)password
             service:(NSString *)serviceName
               group:(nullable NSString *)keychainGroup
       forceUpdating:(BOOL)forceUpdating
               error:(NSError *_Nullable __autoreleasing *)error;

+ (BOOL)deletePasswordForAccount:(NSString *)account
                     serviceName:(NSString *)serviceName
                           group:(nullable NSString *)keychainGroup
                           error:(NSError **)error;
+ (BOOL)clearPasswordsForServiceName:(NSString *)serviceName
                               group:(nullable NSString *)keychainGroup
                               error:(NSError **)error;

@end
NS_ASSUME_NONNULL_END
